﻿using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using ZH.GPT.Infrastructures.Entities;
using ZH.GPT.Infrastructures;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using ZH.GPT.Infrastructures.Repositories;
using ZH.GPT.Infrastructures.Repositories.Interface;
using ZH.GPT.Services.Interface;
using ZH.GPT.Domains.User.Response;
using ZH.GPT.Utils;
using ZH.GPT.Domains;
using ZH.GPT.Domains.User.Request;
using ZH.RetailContainer.CommLibrary.Result;

namespace ZH.GPT.Controllers
{

    /// <summary>
    /// 控制器父类
    /// </summary>
    [ApiController]
    public abstract class BaseController : ControllerBase
    {
        /// <summary>
        /// 返回成功,重写 同string序列化的 才可以使用该方法
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="value"></param>
        /// <param name="state"></param>
        /// <returns></returns>
        [ApiExplorerSettings(IgnoreApi = true)]
        public ContentResult Success<T>(T value, State state = State.Succeed) where T : class
        {
            return Content(PackResult.Pack(value, state).ToString(), "application/json");
        }

        /// <summary>
        /// 返回成功
        /// </summary>
        /// <returns></returns>
        [ApiExplorerSettings(IgnoreApi = true)]
        public ContentResult Success()
        {
            return Content(PackResult.Pack().ToString(), "application/json");
        }


        /// <summary>
        /// 返回错误
        /// </summary>
        /// <param name="code"></param>
        /// <param name="describe"></param>
        /// <returns></returns>
        [ApiExplorerSettings(IgnoreApi = true)]
        public ContentResult Error(ErrorCode code = ErrorCode.System_Error, string describe = "")
        {
            return Content(PackResult.Pack(code, describe).ToString(), "application/json");
        }

    }

}
